/*** 
This do-file combines all ACS State-level variables into a single cleaned dataset.
***/ 

*-------------------------------------------------------------------------------
* Set up
*-------------------------------------------------------------------------------

* Set $root
project figstabs, root
if (r(buildrunning)==0) include "${root}/code/config_interactive.do"

* Run cleaning code for each ACS variable
project, do("${root}/code/ACS 2014-2018 5-Year State/ACS 2014-2018 Median 2BR Rent - Cleaning.do")
project, do("${root}/code/ACS 2014-2018 5-Year State/ACS 2014-2018 Population - Cleaning.do")

* Combine ACS variables
project, uses("${root}/data/derived/ACS 2014-2018 5-Year State/Individual Variables/ACS 2014-2018 Population.dta")
use "${root}/data/derived/ACS 2014-2018 5-Year State/Individual Variables/ACS 2014-2018 Population.dta", clear

foreach file in "Median 2BR Rent" {
	project, uses("${root}/data/derived/ACS 2014-2018 5-Year State/Individual Variables/ACS 2014-2018 `file'.dta")
	merge 1:1 state_fips using "${root}/data/derived/ACS 2014-2018 5-Year State/Individual Variables/ACS 2014-2018 `file'.dta", assert(3) nogen
}

*-------------------------------------------------------------------------------
* Save final file
*-------------------------------------------------------------------------------

save "${root}/data/derived/ACS 2014-2018 5-Year State/ACS 2014-2018 State.dta", replace
project, creates("${root}/data/derived/ACS 2014-2018 5-Year State/ACS 2014-2018 State.dta")
